import axios from "axios"
const base="http://api.callmesoul.cn";
import store from './vuex/store'
axios.interceptors.request.use(
  config => {
    store.commit('SET_LOADING',{loading:true});
    return config;
  });
axios.interceptors.response.use(
  response => {
    store.commit('SET_LOADING',{loading:false});
    return response;
  },
  error => {
    if (error.response) {
      if (error.response.status===403){
        MessageBox.alert('请重新登陆', '登陆超时', {
          confirmButtonText: '确定',
          callback: action => {
            store.dispatch("localLogin","/");
          }
        });
        MessageBox.alert('登陆超时',"请重新登陆").then(action => {
          store.dispatch("localLogin","/");
        });
      }
    }
    return Promise.reject(error.response.data);  // 返回接口返回的错误信息
  });

let Api={
  base:base,
  getMenu:function () {
    return axios.get(base+`/api/v1/menus`);
  },
  getArticle:function (params) {
    return axios.get(base+`/api/v1/articles`,{params:params});
  },
  getArticleDetail:function (id) {
    return axios.get(base+`/api/v1/articles/`+id);
  }
};

export default Api;

